<?php
namespace app\api\controller;

use app\common\controller\Base;
use think\Db;
use app\index\model\ChongZhi;
use app\index\model\TiXian;
use app\index\model\Username;
use app\common\model\StateChange;
use think\Exception;
header("ACCESS-CONTROL-ALLOW-ORIGIN:http://114.215.68.205");

class Member extends Base
{
	public function _initialize(){
		header("Content-type:text/html;charset=utf-8");
		parent::_initialize();
		//用户中心所需参数
		
		$start = array(
				'user_all'                     =>$this->user_all,
				'logo'                          =>$this->logo,
				'app_down'                =>$this->app_down,
				'now_time_windows' => $this->now_time_windows,
				'usnameclass'            => $this->usnameclass,
				'qq_kg'=>$this->qq_kg,
				'wx_kg'=>$this->wx_kg,
				'zxkf'=>$this->zx
		);
		$this->state = new StateChange();
		$this->assign('s',$this->user_all);
		$this->assign($start);
		$this->assign('cur','member');
//验证加密
		/*$VALUE_KEY = ['afewfewfew21342dsaewf'=>'8f4da4f9ew4f98ewq65fwe48f9w'];
		$HEADER_TIME = isset($_SERVER['HTTP_TIME']) ? $_SERVER['HTTP_TIME'] : '';
		$HEADER_KEY = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
		$HEADER_SIGN = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : '';

		$POST_LOGIN_KEY = isset($_SERVER['HTTP_LOGINKEY']) ? $_SERVER['HTTP_LOGINKEY'] : ( isset($_POST['login_key']) ? $_POST['login_key'] : '' );
		$POST_NAME = isset($_SERVER['HTTP_USERNAME']) ? $_SERVER['HTTP_USERNAME'] : (isset($_POST['username']) ? $_POST['username'] : (isset($_POST['name']) ? $_POST['name']:''));


		if( !isset($VALUE_KEY[$HEADER_KEY]) ){
			exit(json_encode(['result'=>0], JSON_UNESCAPED_UNICODE));
		}

		$validation =  $HEADER_TIME.$VALUE_KEY[$HEADER_KEY].$POST_LOGIN_KEY.$POST_NAME;
		if( $HEADER_SIGN != md5($validation) ){
			exit(json_encode(['result'=>0], JSON_UNESCAPED_UNICODE));
		}*/
	}
	public function getTimelyInfo(){

		$name = input('post.username','');
		$login_key = input('post.login_key','');
		if(!$name && !$login_key){
			$ret = array(
					'result'=>1,
					'ResultMsg'=>'未登录',
					'datas'=>['qq_kg'=>$this->qq_kg,
								'wx_kg'=>$this->wx_kg,
								'zxkf'=>$this->zx,
								'xiazurl'=>$this->url['xiazurl']
								]
			);
			return json_encode($ret,JSON_UNESCAPED_UNICODE);
		}
		$info = Db::name('username')->field('je,dl,us_class,czzje,tzzje,dlzyj,tjm')->where(['username'=>$name,'login_key'=>$login_key])->where('open', '<', 1)->find();
		if(empty($info)){
			$ret = array(
					'result'=>0,
					'ResultMsg'=>'用户信息不正确',
					'datas'=>['qq_kg'=>$this->qq_kg,
							'wx_kg'=>$this->wx_kg,
							'zxkf'=>$this->zx
							]
			);
			return json_encode($ret,JSON_UNESCAPED_UNICODE);
		}
		$level = Db::name("us_class")->field("id,class_name,czl,xml")->order("czl asc")->select();
		$current_level = "";
		$next_level = "";
		$next_money = 0;
		$next_xml = 0;
		foreach($level as $k=>$v){
			if( $info['us_class']==$v['id'] && isset($level[$k+1]) ){
				$current_level = $level[$k]['class_name'];
				$next_level = $level[$k+1]['class_name'];
				$next_money = ceil(floatval($level[$k+1]['czl'])-floatval($info['czzje']));
				$next_xml = ceil(floatval($level[$k+1]['xml'])-floatval($info['tzzje']));
				break;
			}
		}

		$count = Db::name('xiaoxi')->where(['username'=>$name,'ifdq'=>0])->count();
		$open = Db::name('agent_off')->where('id',1)->value('open');
		if(strpos($this->url['tuigurl'],'?')!==false){
			$tuig = $this->url['tuigurl'].'&vip='.$info['tjm'];	
		}else{
			$tuig = $this->url['tuigurl'].'?vip='.$info['tjm'];
		}
		$ret = array(
				'result'=>1,
				'ResultMsg'=>'',
				'datas'=>array(
						'money'=>floatval($info['je']),
						'count'=>$count,
						'dl'=>intval($info['dl']),
						'dlopen'=>$open,
						'current_level'=>$current_level,
						'next_level'=>$next_level,
						'next_money'=>$next_money,
						'next_xml'=>$next_xml,
						'dlyj'=>floatval($info['dlzyj']),
						'tjm'=>$info['tjm'],
						'qq_kg'=>$this->qq_kg,
						'wx_kg'=>$this->wx_kg,
						'zxkf'=>$this->zx,
						'xiazurl'=>$this->url['xiazurl'],
						'tuigurl'=>$tuig
				)
		);
		echo json_encode($ret,JSON_UNESCAPED_UNICODE);
	}

	public function bankList(){
		$row = array(
				'result'=>1,
				'ResultMsg'=>'',
				'datas' => Db::name('bank')->select()
		);
		echo json_encode($row,JSON_UNESCAPED_UNICODE);
	}

	public function perfectBank(){

		$username = input('username') ? input('username') : '';
		$login_key = input('post.login_key','');
		$res = Db::name('username')->where(['username'=>$username,'login_key'=>$login_key])->where('open', '<', 1)->find();
		if(empty($res)){
			$ret = array(
					'result'=>0,
					'ResultMsg'=>'用户信息不正确',
			);
			return json_encode($ret,JSON_UNESCAPED_UNICODE);
		}
		$bankuser = input('bankuser') ? input('bankuser') : '';
		$bankname = input('bankname') ? input('bankname') : "";
		$bankno = input('bankno') ? input('bankno') : '';
		$province = input('province') ? input('province') : '';
		$city = input('city') ? input('city') : '';
		$mobile = input('mobile') ? input('mobile') : '';
		$password = input('password') ? input('password') : '';
		$bankaddress = input('bankaddress') ? input('bankaddress') :''; 
		$row = array(
				'result'=>1,
				'ResultMsg'=>'',
		);
		if( $password!=''&& $bankuser!=''&& $province!=''&&$bankno!=''&& $bankname!=''&& $city!=''&& $mobile!='' && $bankaddress!=''){
			if(!checkPhone($mobile)){
				$row['datas'] = 4;//手机号码格式不对
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}
			$count = Db::name("username")->where(['bankno'=>$bankno])->count();
			if( $count > 0 ){
				$row['datas'] = 3; //银行卡不能重复
			}else{
				Db::startTrans();
				try{

					$tixian = new TiXian();
					if( !$tixian->setTixianWithdraw($username, $password, $bankuser, $province, $bankno, $bankname, $city, $mobile,'',$bankaddress) ){
						throw new Exception("银行信息更新错误！");
					}
					$t = Db::name('xt_caijin')->where('id',1)->find();
					if($t['open'] == 0) {
						$je = $t['je'];
						$dml = $t['cj_dml'];
					} else {
						$je = 0;
						$dml = 0;
					}
					$jes = $je+$res['je'];
					$dml = $dml+$res['dml'];
					$zcj = $res['zcjje']+$je;

					if($je>0){
						$data = array('je'=>$jes,'dml'=>$dml,'zcjje'=>$zcj,'reg_je'=>$je,'bk_time'=>time());
						if( !Db::name('username')->where('username',$username)->update($data) ){
							throw new Exception("绑卡赠送信息更新错误！");
						}
						 if(!Db::name('bank_caijin')->insert(array('username'=>$username,'bankje'=>$je,'yue'=>$res['je'],'time'=>time(),'hqfs'=>$t['open']))){
							throw new Exception("添加失败");
						} 
						$state = new StateChange();
						$state->UserFaSong($username,  "您已绑定银行卡，赠送彩金：".$je."元.已到账，请注意查收！");

						$datas = array(
								'username'=>$username,
								'user_class'=>$res['us_class'],
								'cjje'=>$je,
								'fstime'=>time(),
								'beizhu' => '系统赠送，用户绑定银行卡，赠送彩金',
								'czadmin' => '绑卡赠送彩金',
								'cjhje'=>$jes,
						);
						Db::name('caijin_list')->insert($datas);
					}
					Db::commit();
					$row['datas'] = 2;
				}catch (\Exception $e) {
					Db::rollback();

					echo $e->getMessage();
					$row['datas'] = 1;
				}
			}
		}else{
			$row['datas'] = 0;
		}
		echo json_encode($row,JSON_UNESCAPED_UNICODE);
	}

	public function outMoney(){
		$row = array(
				'result'=>1,
				'ResultMsg'=>'',
		);
		if(input('post.')){
			$txje = input('post.txje');
			$password=input('post.password');
			$username = input('username','');
			$login_key = input('post.login_key','');
			$user = Db::name('username')->where(['username'=>$username,'login_key'=>$login_key])->where('open', '<', 1)->find();
			if( empty($user) ){
				$row = ['result'=>0,'ResultMsg'=>'用户信息不正确'];
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}

			if( 1==intval($user['nbzh'])) {
				$row['ResultMsg'] = "内部账号不能提现！";
				$row['datas'] = 11;
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}
			//判断账号是否为冻结或者提现功能是否关闭或者为试玩账号
			if($user['open']==1 || $user['swzh']==1 || $user['tixian_open']==1) {
				$row['ResultMsg'] = "您的账号目前为禁止提现状态！";
				$row['datas'] = 12;
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}

			//验证打码量是否满足要求
			$code_amount = Db::name('xt_dmsz')->find();
			if( 1==intval( $code_amount['tx_yzdml'] ) && floatval($user['dml']) > 0 ) {
				$row['ResultMsg'] = "打码量未通过，您还需消费{$user['dml']}元才能提现！";
				$row['datas'] = 8;
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}

			$c = Db::name('xt_tixian')->where('id',1)->find();
			if ($c['open'] < 1) {
				$row['ResultMsg'] = "提现功能尚未开启！";
				$row['datas'] = 9;
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}
			$now_times = date('Y-m-d') . " 00:00:00";
			$now_times = strtotime($now_times);
			$count = Db::name('tixian_list')->where('username', $username)->where('txtime', '>', $now_times)->count();
			if ($c['txcount'] > 0 && $count >=$c['txcount']) {
				$row['ResultMsg'] = "今日提现次数已用完！";
				$row['datas'] = 10;
				return json_encode($row,JSON_UNESCAPED_UNICODE);
			}

			if(is_numeric($txje)){
				if($c['zxje']<=$txje && $c['zdje']>=$txje){
					if($txje !='' && $password !=''){
						$d = Db::name('username')->where('username',$username)->find();
						$tixian = new TiXian();
						if( $d['ejmm']==$password ){
							if($d['je']>$txje){
								$je = $d['je']-$txje;
								Db::startTrans();
								try {
									$tixian->setTixianJe($username, $txje, '0', '0', time(), get_ip(), '0',$je);
									$tixian->setTixianSaveJe($username, $je);
									Db::commit();
									$row['ResultMsg'] = '已提交提现审核，请耐心等待';
									$row['datas'] = 1;
								} catch (\Exception $e) {
									// 回滚事务
									Db::rollback();
									$row['ResultMsg'] = '提现失败请重试';
									$row['datas'] = 7;
								}
							}else{
								$row['ResultMsg'] = '可提现余额为'.$d['je'].',余额不足';
								$row['datas'] = 6;
							}
						}else{
							$row['ResultMsg'] = '取款密码错误';
							$row['datas'] = 5;
						}
					} else {
						$row['ResultMsg'] = '金额和密码不能为空';
						$row['datas'] = 4;
					}
				} else {
					$row['ResultMsg'] = '提现金额不在提现限额之内';
					$row['datas'] = 3;
				}
			}else{
				$row['ResultMsg'] = '输入正确金额';
				$row['datas'] = 2;
			}
		}else{
			$row['ResultMsg'] = '传入信息不正确';
			$row['datas'] = 0;
		}
		return json_encode($row,JSON_UNESCAPED_UNICODE);
	}

	public function custService(){

		//查询所有客服
		$service = Db::name('xt_kflink')->where(['status'=>1])->whereIn('type',array(1,3))->select();
		$row = array(
				'result'=>1,
				'ResultMsg'=>'',
		);
		$datas = [
			'qq' => [],
			'wx' => []
		];
		foreach($service as $v){
			if( 1==$v['type'] ) $datas['qq'][] = $v['qq'];
			if( 3==$v['type'] ) $datas['wx'][] = $v['qq'];
		}
		$row['datas'] = $datas;
		echo json_encode($row,JSON_UNESCAPED_UNICODE);
	}
	public function index()
	{
		if(!$this->user_all['username']) {
		    $this->redirect('mobile/Member/notlogin');
		}
		$user = $this->user_all['username'];
		//查账号
		$find = Db::name('username')->alias('a')->join('__US_CLASS__ us','a.us_class=us.id')->where('username',$user)->find();
		$xxcount = Db::name('xiaoxi')->where('username',$this->user_all['username'])->order('id','DESC')->limit(50)->select();
		$count = 0;
		foreach ($xxcount as $va){
			if($va['ifdq']==0){
				$count += 1;
			}
		}
		$title = '会员中心';
		$this->assign('count',$count);
		$this->assign('f',$find);
		$this->assign('user',$user);
		$this->assign('title',$title);

		if($find['swzh']) {
		    return $this->fetch('sw_index');
		} else {
		    return $this->fetch();
		}
	}

	public function notlogin() {
	    $title = '会员中心';
	    $this->assign('title',$title);
	    return $this->fetch();
	}

	/**
	 * 充值列表
	 */
	public function chongzhi() {
		if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
		}
		$this->assign('title','充值中心');
		$list = Db::name("pay_method")->where(['status'=>1])->order("seq asc")->select();
		$this->assign('list',$list);

		return $this->fetch("recharge_method");

	    if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
	    }
	    $info = Db::name('pay_xianshang')->field('id,pay_name,open,level')->select();
	    foreach($info as &$v) {
	        $v['level_open'] = 0;
	        $level_arr = explode(',',$v['level']);
	        if(in_array($this->user_all['us_class'],$level_arr)) $v['level_open'] = 1;
	    }
	    $this->assign('title',"充值中心");
	    $this->assign('info',$info);
	    return $this->fetch();
	}
	/**
	 * 线下充值
	 * @param string $je
	 * @param string $liuyan
	 * @param string $zffs
	 * @return Ambigous <\think\mixed, string>
	 */
	public function xxchongzhi($je='',$appDateTime='',$liuyan='',$zffs=''){
		if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
		}
		//区分线下支付方式，默认为银行
		$pay_type = input('get.pay_type') ? input('get.pay_type') : 'bank';
	    if(!in_array($pay_type,['wx','ali','bank'])) $pay_type = 'bank';
		$je = sprintf("%.2f",$je);
		$user = $this->user_all['username'];
		$sw = Db::name('xt_shiwan')->where('id',1)->find();
		$sure = strpos($user, $sw['qianzhui']);
		$query = Db::name('username')->where('username',$user)->find();
		$usclass = input('usclass')?input('usclass'):'';
		$hyzsbs = input('hy_zsbs')?input('hy_zsbs'):'';
		$xsczje = input('xsczje')?input('xsczje'):'';
		$xsczzsbs = input('xsczzsbs')?input('xsczzsbs'):'';
		$xxczje = input('xxczje')?input('xxczje'):'';
		$xxczzsbs = input('xxczzsbs')?input('xxczzsbs'):'';
		$account_id = input('account') ? input('account') : 0;

		//线下账户列表
		$xxlist = Db::name('pay_xxlist')->select();
		foreach($xxlist as $v) {
		    $xxlist_data[$v['xx_remark']][] = $v;
		}

		//会员等级与百分比
		$ts = Db::name('us_class')->where('id',$query['us_class'])->find();

		//判断单次充值是否满一定金额，达到赠送金额；
		$xtcz = StateChange::name('xt_chongzhi')->where('id',1)->find();
		if($sure !== 0){
			//开始处理充值
			if($this->user_all['swzh'] == 1) {
				android_member('试玩账号无法充值！',$this->appfrom);
			}
			//充值提交
			if($query['nbzh']>0){
				if($je !=''){
					$state = new StateChange();
					$where = array('username'=>$user,'nbzh'=>1);
					$savedata = array('je'=>$query['je']+$je,'czzje'=>$query['czzje']+$je);
					$state->SaveRecharge('username', $where, $savedata);
					android_member('操作成功',$this->appfrom);
				}
			}else{
				//判断防骚扰
				$count_sheuid = Db::name('xt_czfsr')->find();
				if($count_sheuid['open'] > 0) {
					$nowys = time() - $count_sheuid['time_xx'] * 60;
					$old_czjl = Db::name('chongzhi_list')->where('username',$this->user_all['username'])->where('cztime','>',$nowys)->find();
					if($old_czjl['id'] > 0) {
						android_member("系统充值防骚扰已开启，{$count_sheuid['time_xx']}分钟内只能充值1次！",$this->appfrom);
					}
				}
				//提交充值
				if($je != '' && $liuyan !='' && $appDateTime !=''){
					$time = strtotime($appDateTime);
					$ddbh = 'S_'.$time.rand(0,999);
					if(!$account_id) {
						mobile_tishi('请选择充值账户', '/api/Member/xxchongzhi?pay_type='.$pay_type,$this->appfrom);
					}
					if($zffs==1) {
					    $xxbank='微信转账';
					    $account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
					    $czclass=2;
					    $czadmin='';
					} elseif($zffs==2) {
					    $xxbank='支付宝转账';
					    $account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
					    $czclass=2;
					    $czadmin='';
					}elseif($zffs==4) {
						$xxbank='QQ转账';
						$account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
						$czclass=2;
						$czadmin='';
					} else {
					    $xxbank='网银转账';
					    $account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
					    $czclass=2;
					    $czadmin='';
					}
					$msje=0;$msbs=0;
					if($czclass==1){
						if($je>=$xsczje){
							$msje = $je*$xsczzsbs/100;
							$msbs = $xsczzsbs;
						}
					}elseif($czclass==2){
						if($je>=$xxczje){
							$msje = $je*$xxczzsbs/100;
							$msbs = $xxczzsbs;
						}
					}
					$zsbs = $hyzsbs;
					$zsje = $je*$hyzsbs/100;
					$chongzhi = new ChongZhi();

					if($je>=10){
						if($chongzhi->WeiXinRecharge($czadmin,$ddbh,$je,$user,'0','0',$czclass,$xxbank,$time,get_ip(),'0',$liuyan,$zsje,$zsbs,$msje,$msbs,$usclass,$account,'0.00',$this->user_all['je'])){
							android_member('提交成功',$this->appfrom);
						}
					}else{
						mobile_tishi('输入正确的金额', '/api/Member/xxchongzhi?pay_type='.$pay_type,$this->appfrom);
					}
				}
			}
			//页面显示
			$title = '充值中心';
			$this->assign('time',time());
			$this->assign('xtcz',$xtcz);
			$this->assign('ts',$ts);
			$this->assign('title',$title);
			$this->assign('xxlist',$xxlist_data);
			if($pay_type == 'wx') {
			    $weixin = Db::name('pay_xxlist')->where('id',1)->find();
			    $this->assign('weixin',$weixin);
			    return $this->fetch('chongzhi_wx');
			}
			if($pay_type == 'ali') {
			    $zhifubao = Db::name('pay_xxlist')->where('id',2)->find();
				$this->assign('zhifubao',$zhifubao);
			    return $this->fetch('chongzhi_ali');
			}
			if($pay_type == 'bank') {
			    $wangyin = Db::name('pay_xxlist')->where('id',3)->find();
			    $this->assign('wangyin',$wangyin);
			    return $this->fetch('chongzhi_bank');
			}
		}else{
			android_member('试玩账号无法充值!',$this->appfrom);
		}
	}

	/**
	 * 高通线上充值
	 */
	public function gtPay() {
	    $id = input('get.id') ? input('get.id') : 0;

	    if(!$this->user_all['username']) {
			mobile_tishi('请先登录账号！','/mobile/user/login',$this->appfrom);return;
	    }
	    if($this->user_all['swzh'] != 0) {
			mobile_tishi('试玩账号无法充值！','/mobile/Member/index',$this->appfrom);return;
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
			mobile_tishi('该支付方式暂未开启！','/mobile/Member/chongzhi',$this->appfrom);return;
	    }

	    $username = $this->user_all['username'];
	    $pay_type = Db::name('pay_type_list')->where(['method'=>1,'mob'=>1])->order('order','DESC')->column('type_name','type_value');

        //页面显示
        $title = '高通支付';
        $this->assign('title',$title);
        $this->assign('username',$username);
        $this->assign('pay_type',$pay_type);
        return $this->fetch('gt_pay');
	}

	/**
	 * 速付线上充值
	 */
	public function sfPay() {
	    $id = input('get.id') ? input('get.id') : 0;

	    if(!$this->user_all['username']) {
			mobile_tishi('请先登录账号！','/mobile/user/login',$this->appfrom);return;
	    }
	    if($this->user_all['swzh'] != 0) {
			mobile_tishi('试玩账号无法充值！','/mobile/Member/index',$this->appfrom);
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
			mobile_tishi('该支付方式暂未开启！','/mobile/Member/chongzhi',$this->appfrom);return;
	    }

	    $username = $this->user_all['username'];
	    $pay_type = Db::name('pay_type_list')->where(['method'=>2,'mob'=>1])->order('order','DESC')->column('type_name','type_value');

	    //页面显示
	    $title = '速付支付';
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('pay_type',$pay_type);
	    return $this->fetch('sf_pay');
	}

	/**
	 * 支付宝扫码充值
	 */
	public function aliCode() {
	    $id = input('get.id') ? input('get.id') : 0;

	    if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
	    }
	    if($this->user_all['swzh'] != 0) {
			android_member('试玩账号无法充值！',$this->appfrom);
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
			android_member('该支付方式暂未开启！',$this->appfrom);
	    }

	    $username = $this->user_all['username'];
	    //线上二维码账户列表
	     $online_ac = Db::name('code_account')->where(['type'=>'alipay','lock'=>0])->select();

	    //页面显示
	    $title = '支付宝扫码';
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('online_ac',$online_ac);
	    return $this->fetch('ali_code');
	}

	/**
	 * 微信扫码充值
	 */
	public function wxCode() {
	    $id = input('get.id') ? input('get.id') : 0;

	    if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
	    }
	    if($this->user_all['swzh'] != 0) {
			android_member('试玩账号无法充值！',$this->appfrom);
	    }
	    $open = Db::name('pay_xianshang')->where('id',$id)->value('open');
	    if(!$open) {
			android_member('该支付方式暂未开启！',$this->appfrom);
	    }
	    $username = $this->user_all['username'];
	    //线上二维码账户列表
	    $online_ac = Db::name('code_account')->where(['type'=>'wechat','lock'=>0])->select();

	    //页面显示
	    $title = '微信扫码';
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('online_ac',$online_ac);
	    return $this->fetch('wx_code');
	}

	/**
	 * 提现页面
	 * @return Ambigous <\think\mixed, string>
	 */
	public function tixian(){
		if(!$this->user_all['username']) {
			mobile_tishi('请先登录账号！','/mobile/user/login',$this->appfrom);return;
		}
		$user = $this->user_all['username'];
		$r = Db::name('xt_shiwan')->where('id',1)->value('qianzhui');
		$sure = strpos($user, $r);
		if($sure !== 0){
			$t = Db::name('username')->where('username',$user)->find();
			if($t['dml']>0){
				mobile_tishi("打码量还剩".$t['dml']."，无法提现.", '/mobile/Member/index',$this->appfrom);
			}else{

				$s = Db::name('xt_tixian')->where('id',1)->find();
				if($s['open'] < 1) {
					mobile_tishi('提现功能尚未开启！','/mobile/Member/index',$this->appfrom);return;
				}
				$now_times = date('Y-m-d')." 00:00:00";
				$now_times = strtotime($now_times);
				$count = Db::name('tixian_list')->where('username',$this->user_all['username'])->where('txtime','>',$now_times)->count();
				if($s['txcount'] > 0) {
					if($count >= $s['txcount']) {
						mobile_tishi('今日提现次数已用完！','/mobile/Member/index',$this->appfrom);return;
					}
				}
				//判断是否绑定银行卡
				if($t['bankren']){$t='display:block;';$t_no='display:none;';}else{$t='display:none;';$t_no='display:block;';}
				$bank = Db::name('bank')->select();
				$title = '在线提款';
				$this->assign('t',$t);
				$this->assign('s',$s);
				$this->assign('t_no',$t_no);
				$this->assign('bank',$bank);
				$this->assign('title',$title);
				return $this->fetch();
			}
		}else{
			mobile_tishi('试玩账号无法提现！','/mobile/Member/index',$this->appfrom);}
	}
	/**
	 * 添加银行卡并且设置付款密码
	 * @param string $ejmm
	 * @param string $bankren
	 * @param string $banksf
	 * @param string $bankno
	 * @param string $bankname
	 * @param string $banksq
	 * @param string $mobile
	 * @param string $qq
	 */
	public function tixianzl($ejmm='',$bankren='',$banksf='',$bankno='',$bankname='',$banksq='',$mobile='',$qq=''){
		if(!$this->user_all['username']) {
			mobile_tishi('请先登录账号！','/mobile/user/login',$this->appfrom);return;
		}
		$user = $this->user_all['username'];
		if($ejmm!=''&&$bankren!=''&&$banksf!=''&&$bankno!=''&&$bankname!=''&&$banksq!=''&&$mobile!=''&&$qq!='')
		{
			$res = Db::name('username')->where('username',$this->user_all['username'])->find();
			$tixian = new TiXian();
			$tixian->setTixianWithdraw($user, $ejmm, $bankren, $banksf, $bankno, $bankname, $banksq, $mobile, $qq);
			$t = Db::name('xt_caijin')->where('id',1)->find();
			if($t['open'] == 1) {
				$je = $t['je'];
				$dml = $t['cj_dml'];
			} else {
				$je = 0;
				$dml = 0;
			}
			$je = $je+$res['je'];
			$dml = $dml+$res['dml'];
			$data = array('je'=>$je,'dml'=>$dml);
			$query = Db::name('username')->where('username',$this->user_all['username'])->update($data);
			if($je>0){
				$this->state->UserFaSong($this->user_all['username'], "您注册账号赠送：".$je."元.已到账，请注意查收！");
			}
			mobile_tishi('绑定银行卡成功', '/mobile/Member/tixian',$this->appfrom);
		}else{
			mobile_tishi('不能为空', '/mobile/Member/tixian',$this->appfrom);
		}
	}
	/**
	 * 提取现金
	 * @param string $txje
	 * @param string $password
	 */
	public function tixianje(){
	    //开启事务
	    Db::startTrans();
	    if(!$this->user_all['username']) {

			mobile_tishi('请先登录账号！','/mobile/user/login',$this->appfrom);return;
		}
		if(input('post.')){

			$txje=input('post.txje');
			$password=input('post.password');

			$user = $this->user_all['username'];
			$c = Db::name('xt_tixian')->where('id',1)->find();
			if(is_numeric($txje)){
				if($c['zxje']<=$txje && $c['zdje']>=$txje){
					if($txje !='' && $password !=''){
						$d = Db::name('username')->where('username',$user)->find();
						$tixian = new TiXian();

						if($d['ejmm']==md5($password)){
								if($d['je']>$txje){
			                        $je = $d['je']-$txje;
			                        try {
			                        	$tixian->setTixianJe($user, $txje, '0', '0', time(), get_ip(), '0');
			                        	$tixian->setTixianSaveJe($user, $je);
			                        	Db::commit();
										mobile_tishi('已提交提现审核，请耐心等待', '/mobile/Member/index',$this->appfrom);
										return;
			                         } catch (\Exception $e) {
			                             // 回滚事务
			                             Db::rollback();
										mobile_tishi('提现失败请重试', '/mobile/Member/index',$this->appfrom);
										return;
			                         }
								}else{
									mobile_tishi('可提现余额为'.$d['je'].',余额不足', '/mobile/Member/tixian',$this->appfrom);
								}

						}else{
							mobile_tishi('取款密码错误', '/mobile/Member/tixian',$this->appfrom);
						}
					} else {
						mobile_tishi('不能为空', '/mobile/Member/tixian',$this->appfrom);
					}
				} else {
					mobile_tishi('提现金额不在提现限额之内', '/mobile/Member/tixian',$this->appfrom);
				}
			}else{

				mobile_tishi('输入正确金额', '/mobile/Member/tixian',$this->appfrom);
			}
		}

	}
	/**
	 * 更改密码
	 */
	public function passxg(){
		$user = $this->user_all['username'];
		$r = Db::name('xt_shiwan')->where('id',1)->value('qianzhui');
		$sure = strpos($user, $r);
		if($sure !== 0){
			$title = '修改密码';
			$this->assign('title',$title);
			return $this->fetch();
		}else
			mobile_tishi('试玩账号无法提现！','/mobile/Member/index',$this->appfrom);
	}
	/**
	 * 更改密码和提款密码
	 * @param string $old_password
	 * @param string $new_password
	 * @param string $new_password2
	 * @param string $passwordclass
	 */
	public function passxgmm(){
		if(!$this->user_all['username']) {
			mobile_tishi('请先登录账号！','/mobile/user/login',$this->appfrom);return;
		}
		$old_password = input('old_password');
		$new_password = input('new_password');
		$new_password2 = input('new_password2');
		$passwordclass = input('passwordclass');
		if($passwordclass == 1){
		    $password = 'password';
		    $password_model = 'updatePass';
		}else if($passwordclass == 2){
		    $password = 'ejmm';
		    $password_model = 'updatePassEjmm';
		}
		$user = $this->user_all['username'];

		$user_find = Db::name('username')->where('username',$user)->field($password)->find();
		if(md5($old_password) == $user_find[$password]){
		    $ps = new Username();
		    $ps->$password_model($user, md5($new_password));
		    $this->success('修改成功');
		}else{
		    $this->error('旧密码不一致');
		}

	}
	/**
	 * 手机版投注记录
	 * @return Ambigous <\think\mixed, string>
	 */
	public function touzhu()
	{
		if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
		}
        //接收所需参数
        $tzid = input('tzid') ? input('tzid') : '';
        $czid = input('czid') ? input('czid') : '';
        $classtz = input('classtz') ? input('classtz') : '0';
        $timebh = input('timebh') ? input('timebh') : '1';
        $page = input('page') ? input('page') : 1;
        if($page < 1) $page = 1;
        $page_num = 10;
        //标记当前导航栏
        $this->assign('current','call');
        /* ------------------------------------------------投注记录详情----------------------------------------------- */
        //根据条件查询
        if($tzid  && $czid ) {
            if($this->user_all['nbzh'] == 1 || $this->user_all['swzh'] == 1) {
                 $yxsql_mysq="touzhu_list_sw";
             } else {
                 $yxsql_mysq="touzhu_list_ok";
             }
             //正常的订单
             $dingdan = Db::name('touzhu_list_no')->where("id={$tzid} AND username='{$this->user_all['username']}' AND czid={$czid}")->find();

             $dingdanzt = '待开奖';

             if(!$dingdan) {
                 $dingdan = Db::name($yxsql_mysq)->where("id={$tzid} AND username='{$this->user_all['username']}' AND czid={$czid}")->find();
             }

             //追号的订单
             if(!$dingdan) {
                 $dingdan = Db::name('touzhu_list_zh')->where("id={$tzid} AND username='{$this->user_all['username']}' AND czid={$czid}")->find();

                 $dingdanzt = '追号，待开奖';
             }
             $cnzmshdui = Db::name('caipai_list')->where('id',$czid)->find();
             if($cnzmshdui['cp_name_new'] == '') $cnzmshdui['cp_name_new'] = $cnzmshdui['cp_name_old'];
             //投注规格
             if($dingdan['nbzh'] == 1) $tzmss = '元';
             if($dingdan['nbzh'] == 2) $tzmss = '角';
             if($dingdan['nbzh'] == 3) $tzmss = '分';
             //判断是否开奖
             if($dingdan['kjjg'] < 1){
             	$kjjg = '未开奖';
             }else{
             	$kjjg = kjjg_split($dingdan['kjjg'], $dingdan['czid']);

             	if($dingdan['zjje']>0.001){

             		$dingdanzt = '已中奖';

             	}else{
             		$dingdanzt = '未中奖';
             	}
             }

             //获取开奖时间
             $dingdan['tz_time'] = date('Y-m-d H:i:s',$dingdan['tz_time']);
             //投注玩法
             if($dingdan['wfid'] > 0) {
                 $wfnames = Db::name('play_classify')->where('id',$dingdan['wfid'])->find();
             }
             if(!$wfnames['class_name_mini']) $wfnames['class_name_mini'] = $dingdan['tzhm'];
             if(!empty($wfnames['digit'])){
                 $dingdan['tzhm'] = digit($dingdan['tzhm'],$wfnames['digit'],$czid,$wfnames['id']);
             }

             $title= '投注记录';
             $this->assign('title',$title);
             $this->assign('kjjg',$kjjg);
             $this->assign('cnzmshdui',$cnzmshdui);
             $this->assign('dingdan',$dingdan);
             $this->assign('wfnames',$wfnames);
             $this->assign('tzmss',$tzmss);
             $this->assign('dingdanzt',$dingdanzt);
             return $this->fetch('touzhuxx');
         }

         /* ------------------------------------------------投注记录列表----------------------------------------------- */

		 $all_cz_list = Db::name('caipai_list')->where('cp_if_open','<',2)->select();
		 $touzhu_all = $this->touzhuJilu($this->user_all['username'],$timebh,$czid,$classtz);
		 if(count($touzhu_all) > 0) {
		     $touzhu_all = multi_array_sort($touzhu_all,'tz_time');
		 }

		 $zcount = count($touzhu_all);
		 $zys = ceil($zcount / $page_num);
		 if($page > $zys) $page = $zys;
		 $openjl = ($page - 1) * $page_num;
		 $touzhu_all = array_slice($touzhu_all,$openjl,$page_num);

		 $czids = '';
		 $wfids = '';
         foreach($touzhu_all as &$xh_1) {
		    $czids .= $xh_1['czid'].',';
		    $wfids .= $xh_1['wfid'].',';
			$xh_1['tz_time'] = date('Y-m-d H:i:s',$xh_1['tz_time']);
         }

		$title= '投注记录';
		$this->assign('title',$title);
         $this->assign('tzid',$tzid);
         $this->assign('czid',$czid);
         $this->assign('classtz',$classtz);
         $this->assign('timebh',$timebh);
         $this->assign('zongcount',$zcount);
         $this->assign('zys',$zys);
         $this->assign('page',$page);
         $this->assign('list_ca',$all_cz_list);
		 $this->assign('touzhulist',$touzhu_all);
         return $this->fetch('touzhu');
	}
	/**
	 * 手机版用户提现记录
	 * @return Ambigous <\think\mixed, string>
	 */
	/* public function tixianjilvs()
	{
		if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
        }
        $page = input('page') ? input('page') : 1;
        $page_num = 10;
        //查询提现记录
        $tixianjl = $this->tixianjl($this->user_all['username']);
        //总页数
        $zcount = count($tixianjl);
        $zys = ceil($zcount / $page_num);
        //页数限制
        if($page > $zys) $page = $zys;
        if($page < 1) $page = 1;
        $offset = ($page - 1) * $page_num;
        //处理提现记录
        if(count($tixianjl) > 0) {
            $tixianjl = multi_array_sort($tixianjl,'txtime');
        }
        $tixianjl = array_slice($tixianjl,$offset,$page_num);
        foreach($tixianjl as &$xh_1) {
            if($xh_1['zt'] == '1') $xh_1['zt'] = '成功';
            if($xh_1['zt'] == '0') $xh_1['zt'] = '处理中';
            $xh_1['txtime'] = date('m-d H:i:s',$xh_1['txtime']);
        }
        $this->assign('current','drawMoney');
        $this->assign('zys',$zys);
        $this->assign('zcount',$zcount);
        $this->assign('page',$page);
        $this->assign('touzhulist',$tixianjl);
        return $this->fetch('tixianjl');
	} */
	public function tixianjilv(){
		
		$post = input('post.');
		$username = isset($post['username']) ? $post['username'] : '';
		$page = isset($post['page']) ? $post['page'] : '1';
		$limit = 4;
		$ret = array(
				'result'=>0,
				'ResultMsg'=>'无信息',
		);
		if(!empty($username)){
			
			$list = $this->tixianjl($username);
			$zcount = count($list);
			if($page < 1) $page = 1;
			$offset = ($page - 1) * $limit;
			if($zcount>0){
				$list = multi_array_sort($list, 'txtime');
			}
			if($zcount<$offset){
				$list=array();
			}else{
				$list = array_slice($list, $offset,$limit);
				foreach ($list as &$item){
					if($item['zt'] == '1') $item['zt'] = '成功';
					if($item['zt'] == '0') $item['zt'] = '处理中';
					$item['ddbh'] = 'TX_'.$item['txtime'].$item['id'];
					$item['txtime'] = date('m-d H:i',$item['txtime']);
					
				}
			}
			
			$ret = array(
					'result'=>1,
					'ResultMsg'=>'',
					'datas' => $list
			);
		}
		echo json_encode($ret,JSON_UNESCAPED_UNICODE);
	}
	/**
	 * 手机版充值记录
	 * @return Ambigous <\think\mixed, string>
	 */
	/* public function payjls(){

		if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
		}
		$page = input('page') ? input('page') : 1;
		$page_num = 10;
		//总页数
		$zcount = Db::name('chongzhi_list')->where('username',$this->user_all['username'])->count();
		$zys = ceil($zcount / $page_num);
		//页数限制
		if($page > $zys) $page = $zys;
		if($page < 1) $page = 1;
		//查询充值记录
		$offset = ($page - 1) * $page_num;
		$payjls = Db::name('chongzhi_list')->where('username',$this->user_all['username'])->order('id','DESC')->limit($offset,$page_num)->select();
		foreach($payjls as &$py) {
			$py['cztime'] = date('m-d H:i:s',$py['cztime']);
			if($py['czclass']==1) $py['czclass'] = $py['xxbank'];//线上
			if($py['czclass']==2) $py['czclass'] = $py['xxbank'].'(线下充值)';//线下
			if($py['czclass']==3) $py['czclass'] = '手工充值';
			if($py['zt'] == 1) {
				$py['zt'] = '已到账';
			} elseif($py['zt']== '-1'||$py['zt']==9) {
				$py['zt'] = '充值失败';
			}else{
				$py['zt'] = '处理中';
			}
		}
		$this->assign('current','recharge');
		$this->assign('zys',$zys);
		$this->assign('zcount',$zcount);
		$this->assign('page',$page);
		$this->assign('touzhulist',$payjls);
		return $this->fetch();
	} */
	public function payjl(){
		$post = input('post.');
		$page = isset($post['page'])?$post['page']:'1';
		$username = isset($post['username']) ? $post['username'] : '';
		$limit = 10;
		$ret = array(
				'result'=>0,
				'ResultMsg'=>'无信息',
		);
		if(!empty($username)){
			$list = Db::name('chongzhi_list')->field('ddbh,cztime,zt,czclass,je,hy_zsje,hy_msje,xxbank')->where('username',$username)->where('zt','neq',9)->order('id','DESC')->page($page,$limit)->select();
			foreach ($list as &$value){
				$value['cztime'] = date('m-d H:i',$value['cztime']);
				if($value['czclass']==1) $value['czclass'] = $value['xxbank'];//线上
				if($value['czclass']==2) $value['czclass'] = $value['xxbank'].'(线下充值)';//线下
				if($value['czclass']==3) $value['czclass'] = '手工充值';
				if($value['zt'] == 1) {
					$value['zt'] = '已到账';
				} elseif($value['zt']== '-1') {
					$value['zt'] = '充值失败';
				}else{
					$value['zt'] = '处理中';
				}
			}
			$ret = array(
					'result'=>1,
					'ResultMsg'=>'',
					'datas' => $list
			);
		}
		echo json_encode($ret,JSON_UNESCAPED_UNICODE);
		
	}
	/**
	 * 手机版系统发放彩金
	 */
	public function caijin()
	{
		if(!$this->user_all['username']) {
			echo '<script>alert("请先登录账号！");</script>';return;
		}
		$page = input('page') ? input('page') : 1;
		$page_num = 10;
		//查询总页数
		$zcount = Db::name('caijin_list')->where('username',$this->user_all['username'])->count();
		$zys = ceil($zcount / $page_num);
		//页数限制
		if($page > $zys) $page = $zys;
		if($page < 1) $page = 1;
		//查询彩金记录
		$offset = ($page - 1) * $page_num;
		$payjls = Db::name('caijin_list')->where('username',$this->user_all['username'])->order('id','DESC')->limit($offset,$page_num)->select();
		foreach($payjls as &$v) {
			$v['fstime'] = date('m-d H:i:s',$v['fstime']);
		}
		$this->assign('current','bounty');
		$this->assign('zys',$zys);
		$this->assign('zcount',$zcount);
		$this->assign('page',$page);
		$this->assign('touzhulist',$payjls);
		return $this->fetch();
	}

	public function xiaoxi(){
		if(!$this->user_all['username']) {
			android_login('请先登录账号！',$this->appfrom);
		}
		//消息列表
		$data=array('ifdq'=>1);
		$xx_listdb = Db::name('xiaoxi')->where('username',$this->user_all['username'])->order('id','DESC')->select();
		Db::name('xiaoxi')->where('username',$this->user_all['username'])->update($data);
		foreach($xx_listdb as &$v) {
		    $v['xx_time'] = date('Y-m-d H:i:s',$v['xx_time']);
		}
		unset($v);
		$this->assign('current','message');
		$this->assign('xiaoxi_ls',$xx_listdb);
		return $this->fetch();
	}
/**
 * 代理
 */
	public function daili(){
		$title= '代理';
		$this->assign('title',$title);
		return $this->fetch();
	}
	public function dailiCenter(){

		return $this->fetch('dailizhongxin');
	}

	public function dailishuoming(){

		return $this->fetch();
	}

	public function dailibaobiao(){

		$user = input('user')?input('user'):'';
		$start=0;
		$end=time();

		if(input('day')=='' || input('day')=='今天'){
			$start = strtotime(date('Y-m-d').' 00:00:00');
			$end = strtotime(date('Y-m-d').' 23:59:59');

		}
		if(input('day')=='昨天'){
			$start = strtotime(date("Y-m-d",strtotime("-1 day")).' 00:00:00');
			$end = strtotime(date("Y-m-d",strtotime("-1 day")).' 23:59:59');

		}
		if(input('day')=='本周'){
			$start = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)).' 00:00:00');
			$end = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)).' 23:59:59');

		}
		if(input('day')=='本月'){
			$start = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')).' 23:59:59');

		}
		if(input('day')=='上月'){
			$start = strtotime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01 00:00:00'))).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400).' 23:59:59');

		}
		$time = [$start,$end];

		if($user != ''){
			$count = $this->dlXiaJiZongRenShu($user,$time);
		}else{
			$count = $this->dlXiaJiZongRenShu($this->user_all['username'],$time);
		}

		$yj = Db::name('agent_balance')->where('agent',$this->user_all['username'])->whereTime('add_time','BETWEEN',$time)->value('SUM(balance)');
		$this->assign('yj',sprintf('%.2f',$yj));
		$this->assign('count',$count);
		$this->assign('user',$user);
		$this->assign('day',input('day'));
		return $this->fetch();
	}

	public function LowerlevelReport(){
		$username = input('user');
		if($username){
			$user = Db::name('username')->where(['tjr'=>$username])->select();
		}else{
			$user = Db::name('username')->where(['tjr'=>$this->user_all['username']])->select();
		}
		foreach ($user as &$v){
			$yj = Db::name('agent_balance')->where('agent',$v['username'])->value('SUM(balance)');
			$v['sy'] = sprintf('%.2f',$yj);
		}
		$this->assign('user',$user);
		return $this->fetch('xiajibaobiao');
	}
	function dlXiaJiZongRenShu($user,$time){
		static $count = 0;
		static $tzje = 0;
		static $zjje = 0;
		static $hdlj = 0;
		static $tzrs = 0;
		static $txje = 0;
		static $czje = 0;
		static $czrs = 0;
		static $tdye = 0;
		$dl = Db::name('username')->where('username',$user)->value('fandian');
		$count = Db::name('username')->where('tjr',$user)->where('reg_time','BETWEEN',$time)->count();
		$us = Db::name('username')->field('username,dl,xjrens')->where('tjr',$user)->select();
		foreach ($us as $val){
			$tdye += Db::name('username')->where('username',$val['username'])->whereTime('reg_time','BETWEEN',$time)->value('SUM(je)');
			$je = Db::name('touzhu_list_ok')->where('username',$val['username'])->whereTime('tz_time','BETWEEN',$time)->value('SUM(tzje)');
			$tzje += $je;
			$cz = Db::name('chongzhi_list')->where(['username'=>$val['username'],'zt'=>1,'czadmin'=>['<>','']])->whereTime('cztime','BETWEEN',$time)->value('SUM(je)');
			$czje += $cz;
			$txje += Db::name('tixian_list')->where(['username'=>$val['username'],'zt'=>1,'shadmin'=>['<>',''],'czadmin'=>['<>','']])->whereTime('txtime','BETWEEN',$time)->value('SUM(txje)');
			$zjje += Db::name('touzhu_list_ok')->where('username',$val['username'])->whereTime('tz_time','BETWEEN',$time)->value('SUM(zjje)');
			$hdlj += Db::name('caijin_list')->where('username',$val['username'])->whereTime('fstime','BETWEEN',$time)->value('SUM(cjje)');
			if($je){$tzrs += 1;}
			if($cz){$czrs += 1;}
			if($val['dl']==1){
				$this->dlXiaJiZongRenShu($val['username'],$time);
			}
		}
		return array('fandian'=>$dl,'tdye'=>$tdye,'czje'=>$czje,'czrs'=>$czrs,'count'=>$count,'tzje'=>$tzje,'zjje'=>$zjje,'cjje'=>$hdlj,'tzrs'=>$tzrs,'txje'=>$txje);
	}

	public function xiajiguanli(){
		$username = input('user');
		if($username){
			$user = Db::name('username')->where(['tjr'=>$username])->select();
		}else{
			$user = Db::name('username')->where('tjr',$this->user_all['username'])->select();
		}
		foreach ($user as &$v){
			$v['rs'] = $this->dlXiaJiZongRenShu($v['username'], [0,time()]);
		}

		$this->assign('user',$user);
		return $this->fetch();
	}

	public function touzhumingxi(){
		$start=0;
		$end=time();
		$user = '';
		if(input('user')){
			$user = input('user');
		}
		if(input('day')=='' || input('day')=='今天'){
			$start = strtotime(date('Y-m-d').' 00:00:00');
			$end = strtotime(date('Y-m-d').' 23:59:59');

		}
		if(input('day')=='昨天'){
			$start = strtotime(date("Y-m-d",strtotime("-1 day")).' 00:00:00');
			$end = strtotime(date("Y-m-d",strtotime("-1 day")).' 23:59:59');

		}
		if(input('day')=='本周'){
			$start = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)).' 00:00:00');
			$end = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)).' 23:59:59');

		}
		if(input('day')=='本月'){
			$start = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')).' 23:59:59');

		}
		if(input('day')=='上月'){
			$start = strtotime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01 00:00:00'))).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400).' 23:59:59');

		}
		$time = [$start,$end];

		$touzhu = array();
		$us = '';
		if($user!=''){
			$tzmx = Db::name('username')->field('username')->where('username',$user)->select();
		}else{
			$tzmx = Db::name('username')->field('username')->where('tjr',$this->user_all['username'])->select();
		}
		foreach ($tzmx as $v){
			$us .=$v['username'].',';
		}
		$touzhu['dkj'] = Db::name('touzhu_list_no')->where('username','IN',$us)->whereTime('tz_time','BETWEEN',$time)->select();
		$touzhu['yzj'] = Db::name('touzhu_list_ok')->where('username','IN',$us)->whereTime('tz_time','BETWEEN',$time)->where('zjje','0')->select();
		$touzhu['wzj'] = Db::name('touzhu_list_ok')->where('username','IN',$us)->whereTime('tz_time','BETWEEN',$time)->where('zjje','>','0')->select();
		$this->assign('day',input('day'));
		$this->assign('touzhu',$touzhu);
		$this->assign('user',$user);
		return $this->fetch();
	}

	public function jiaoyimingxi(){
		$start=0;
		$end=time();
		$user = '';
		if(input('user')){
			$user = input('user');
		}
		if(input('day')=='' || input('day')=='今天'){
			$start = strtotime(date('Y-m-d').' 00:00:00');
			$end = strtotime(date('Y-m-d').' 23:59:59');

		}
		if(input('day')=='昨天'){
			$start = strtotime(date("Y-m-d",strtotime("-1 day")).' 00:00:00');
			$end = strtotime(date("Y-m-d",strtotime("-1 day")).' 23:59:59');

		}
		if(input('day')=='本周'){
			$start = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)).' 00:00:00');
			$end = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)).' 23:59:59');

		}
		if(input('day')=='本月'){
			$start = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')).' 23:59:59');

		}
		if(input('day')=='上月'){
			$start = strtotime(date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01 00:00:00'))).' 00:00:00');
			$end = strtotime(date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400).' 23:59:59');

		}
		$time = [$start,$end];

		$jiaoyi = array();
		$us = '';
		if($user!=''){
			$tzmx = Db::name('username')->field('username')->where('username',$user)->select();
		}else{
			$tzmx = Db::name('username')->field('username')->where('tjr',$this->user_all['username'])->select();
		}
		foreach ($tzmx as $v){
			$us .=$v['username'].',';
		}
		$jiaoyi['chongzhi'] = Db::name('chongzhi_list')->where('username','IN',$us)->whereTime('cztime','BETWEEN',$time)->select();
		$jiaoyi['tixian'] = Db::name('tixian_list')->where('username','IN',$us)->whereTime('txtime','BETWEEN',$time)->select();
		$this->assign('day',input('day'));
		$this->assign('jiaoyi',$jiaoyi);
		$this->assign('user',$user);
		return $this->fetch();
	}

	public function xiajikaihu(){
		if(input('number')){
			$fandian = input('number');
			$yqm = $this->code();
			$u = Db::name('username')->where('username',$this->user_all['username'])->field('tjm,fandian')->find();
			$date = array('tjm'=>$u['tjm'].'|'.$yqm.'-'.$fandian);
			if(Db::name('username')->where('username',$this->user_all['username'])->update($date)){
				mobile_alert('生成成功','xiajikaihu',$this->appfrom);return;
			}else{
				mobile_alert('生成失败','xiajikaihu',$this->appfrom);return;
			}
		}else{
			$user = Db::name('username')->where('username',$this->user_all['username'])->find();
			$tjm = explode('|',$user['tjm']);
			$tjm_new = array();
			$tjm_old = '';
			foreach ($tjm as $v){
				if(strpos($v, '-')!==false){
					$tjm_new[]=explode('-', $v);
				}else{
					$tjm_old = $v;
				}
			}
			$ymxz = Db::name('dl_domain')->where('status',1)->select();
			$this->assign('tjmold',$tjm_old);
			$this->assign('ymxz',$ymxz);
			$this->assign('tjm',$tjm_new);
			$this->assign('user',$user);
			return $this->fetch();
		}
	}
	public function shenqing(){
		$user = Db::name('username')->where('username',$this->user_all['username'])->value('dlshstatus');
		$this->assign('user',$user);
		return $this->fetch();
	}
	public function shenqingapply(){
		$data['dlshstatus']=1;
		if(Db::name('username')->where('username',$this->user_all['username'])->update($data)){
			echo 1;
		}else{
			echo 0;
		}
	}
	function code(){
		$code=rand('000000','999999');
		/* for($i=1;$i<=2;$i++){
			$code .= chr(rand(97,122));
		}
		for($i=1;$i<=1;$i++){
			$code .= chr(rand(65,90));
		}
		for($i=1;$i<=1;$i++){
			$code .= chr(rand(97,122));
		}
		for($i=1;$i<=4;$i++){
			$code .= chr(rand(65,90));
		}
		for($i=1;$i<=2;$i++){
			$code .= chr(rand(97,122));
		}
		for($i=1;$i<=3;$i++){
			$code .= chr(rand(65,90));
		} */
		if($code != ''){
			$yzm = Db::name('username')->field('tjm')->select();
			$tjm = '';
			foreach ($yzm as $v){$tjm .= $v['tjm'].'--';}
			if(strstr($tjm, $code)!==false){
				$this->code();
			}
		}
		return $code;
	}
	public function qita(){
		$title= '系统彩金';
		$page = input('page') ? input('page') : 1;
		$page_num = 12;
		//查询总页数
		$zcount = Db::name('caijin_list')->where('username',$this->user_all['username'])->where('cjje','>','0')->count();
		$zcount += Db::name('fs_list')->where('username',$this->user_all['username'])->where('fsje','>','0')->count();
		$zcount +=  Db::name('agent_balance')->where('agent',$this->user_all['username'])->where('balance','>','0')->count();
		$zcount +=  Db::name('bonus_user')->where('username',$this->user_all['username'])->where('je','>','0')->count();
		$zcount +=  Db::name('username')->where('username',$this->user_all['username'])->where('reg_je','>','0')->count();
		$zys = ceil($zcount / $page_num);
		//页数限制
		if($page > $zys) $page = $zys;
		if($page < 1) $page = 1;
		//查询彩金记录

		$offset = ($page - 1) * $page_num;
		$cj = Db::name('caijin_list')->field('cjje as je,beizhu as way,fstime as time')->where('username',$this->user_all['username'])->where('cjje','>','0')->order('fstime','DESC')->limit($offset,$page_num)->select();
		$fs = Db::name('fs_list')->field('fsje as je,"返水" as way,distribute_time as time')->where('username',$this->user_all['username'])->where('fsje','>','0')->order('distribute_time','DESC')->limit($offset,$page_num)->select();
		$agent = Db::name('agent_balance')->field('balance as je,"返佣" as way,add_time as time')->where('agent',$this->user_all['username'])->where('balance','>','0')->order('add_time','DESC')->limit($offset,$page_num)->select();
		$bonus = Db::name('bonus_user')->field('je,"红包" as way,time')->where('username',$this->user_all['username'])->where('je','>','0')->order('time','DESC')->limit($offset,$page_num)->select();
		$bk = Db::name('username')->field('reg_je as je,"绑卡彩金" as way,bk_time as time')->where('username',$this->user_all['username'])->where('reg_je','>','0')->select();

		$payjls = array_merge($bk,$cj,$fs,$agent,$bonus);
		if(isset($payjls[0])){
			$payjls = arraySequence($payjls,'time');
		}
		$this->assign('title',$title);
		$this->assign('current','bounty');
		$this->assign('zys',$zys);
		$this->assign('zcount',$zcount);
		$this->assign('page',$page);
		$this->assign('touzhulist',$payjls);
		return $this->fetch();
	}
	public function degree(){
		$usclass = Db::name('us_class')->select();
		
		$this->assign('usclass',$usclass);
		return $this->fetch();
	}
	public function rechargeMethod(){
		$this->assign('title','充值中心');
		$list = Db::name("pay_method")->where(['status'=>1])->order("seq asc")->select();
		$this->assign('list',$list);
		return $this->fetch("recharge_method");
	}
	public function rechargeList(){
		$type = input('type',0);
		$name =$this->user_all['username'];
		if( empty($name)) {
			android_login('请先登录账号！',$this->appfrom);
		}
		$type = intval($type);
		$method = Db::name('pay_method')->find($type);
//		if( empty($method) || 0==intval($method['status'])) {
//			js_tishi('请选中正确支付方案！','/mobile/member/rechargeMethod');exit;
//		}
		$level = $this->user_all['us_class'];
		//线上第三方
		$onBand = Db::name('pay_type_list')->alias("a")
				->join("__PAY_XIANSHANG__ b",'a.method=b.id','LEFT')
				->where(['a.method_id'=>$type,'a.mob'=>1,'b.open'=>1])
				->field("a.id,b.pay_name,a.type_name,a.type_value ,b.level,1 as method, 0 as controller")
				->select();

		foreach( $onBand as $k=>$v ){
			$levelAttr = explode(',',$v['level']);
			$onBand[$k]['controller'] = ChineseToPY($v['pay_name']);
			unset($onBand[$k]['level']);
			if( !in_array($level,$levelAttr) ) unset($onBand[$k]);
		}
		//线上支付宝或微信

		$onThird = Db::name("pay_xianshang")->where(['open'=>1,'is_code'=>1])->field("id,pay_name,level,0 as type_value,2 as method,0 as controller")->select();
		$hasUser = Db::name("code_account")->where(['method_id'=>$type])->group("type")->column("type,count(*) as num");
		foreach( $onThird as $k=>$v ){
			$user_key = $v['pay_name']=="微信扫码" ? "wechat" : 'alipay';
			if( !isset($hasUser[$user_key]) && empty($hasUser[$user_key]) ){
				unset($onThird[$k]);
				continue;
			}
			$levelAttr = explode(',',$v['level']);
			unset($onThird[$k]['level']);
			if( !in_array($level,$levelAttr) ){
				unset($onThird[$k]);
				continue;
			}
		}
		//线下支付
		$offThird = Db::name("pay_xxlist")->where(['method_id'=>$type,'status'=>1])->field("id,xx_name as type_name,0 as type_value,xx_weixin,xx_qq,xx_zhifubao,xx_wangyin,3 as method,0 as controller")->select();
		foreach($offThird as &$v){
			if( 1==intval($v['xx_weixin']) ) $v['pay_name'] = '微信';
			if( 1==intval($v['xx_zhifubao']) ) $v['pay_name'] = '支付宝';
			if( 1==intval($v['xx_wangyin']) ) $v['pay_name'] = '银联';
			if( 1==intval($v['xx_qq']) ) $v['pay_name'] = 'QQ';
			unset($v['xx_weixin']);
			unset($v['xx_zhifubao']);
			unset($v['xx_wangyin']);
			unset($v['xx_qq']);
		}
		unset($v);
		$list = array_merge($onBand,$onThird,$offThird);
		$money = Db::name('username')->where('username',$name)->value('je');
		$this->assign('title',$method['name']);
		$this->assign('money',$money);
		$this->assign('name',$name);
		$this->assign('list',$list);
		return $this->fetch("recharge_list");
	}

	public function getOfflineMessage(){
		$id = input('post.id',0);
		if( empty($id) ){
			return json_encode(['status'=>0,'msg'=>'支付方案错误，请重新选择']);
		}
		$info = Db::name("pay_xxlist")->find($id);
		return json_encode(['status'=>1,'data'=>$info]);
	}
	public function offLineRecharge(){

		$user = $this->user_all;
		if( !$user ) {
			return json_encode(['status'=>0,'msg'=>'请重新登录']);
		}
		//开始处理充值
		if( intval($user['swzh']) == 1) {
			return json_encode(['status'=>0,'msg'=>'试玩账号无法充值']);
		}
		$type = input('post.type',0);  //1:微信；2：支付宝：3：银行
		if( empty($type) ){
			return json_encode(['status'=>0,'msg'=>'支付方案错误，请重新选择']);
		}
		$money  = floatval(input('post.money',0));
		if( $money < 10 ){
			return json_encode(['status'=>0,'msg'=>'请输入正确金额']);
		}

		//内部账户
		if( intval($user['nbzh']) > 0 ){
			$state = new StateChange();
			$where = array('username'=>$user['username'],'nbzh'=>1);
			$state->SaveRecharge('username', $where, array('je'=>floatval($user['je'])+$money,'czzje'=>floatval($user['czzje'])+$money));
			return json_encode(['status'=>1]);
		}else{
			//判断防骚扰
			$count_sheuid = Db::name('xt_czfsr')->find();
			if($count_sheuid['open'] > 0) {
				$nowys = time() - $count_sheuid['time_xx'] * 60;
				$old_czjl = Db::name('chongzhi_list')->where('username',$user['username'])->where('cztime','>',$nowys)->find();
				if( !empty($old_czjl) ) {
					return json_encode(['status'=>0,'msg'=>"系统充值防骚扰已开启，{$count_sheuid['time_xx']}分钟内只能充值1次！"]);
				}
			}

			//会员等级与百分比
			$ts = Db::name('us_class')->where('id',$user['us_class'])->find();
			$usclass = '';
			$hyzsbs = 0;
			if( !empty($ts) ){
				$usclass = $ts['id'];
				$hyzsbs = $ts['czzsbl'];
			}
			//判断单次充值是否满一定金额，达到赠送金额；
			$xtcz = StateChange::name('xt_chongzhi')->where('id',1)->find();
			$xxczje = 0;
			$xxczzsbs = 0;
			if( !empty($xtcz) ){
				$xxczje = $xtcz['xxcz_je'];
				$xxczzsbs = $xtcz['xxcz_zs'];
			}
			$liuyan = input('post.remark','');
			if( empty($liuyan) ){
				return json_encode(['status'=>0,'msg'=>'请输入验证信息']);
			}
			$enter_time = input('post.time','');
			if( empty($enter_time) ){
				return json_encode(['status'=>0,'msg'=>'请选择存入时间']);
			}
			//提交充值
			$time = strtotime($enter_time);
			$ddbh = 'S_'.$time.rand(0,999);
			$account_id = input('post.account',0);
			if( empty($account_id) ) {
				return json_encode(['status'=>0,'msg'=>'请选择充值账户！']);
			}
			$account = Db::name('pay_xxlist')->where('id',$account_id)->value('xx_bankren');
			$xxbank='';
			switch( intval($type) ){
				case 1:
					$xxbank='微信转账';
					break;
				case 2:
					$xxbank='支付宝转账';
					break;
				case 3:
					$xxbank='网银转账';
					break;
				case 4:
					$xxbank='QQ转账';
					break;
			}
			$czadmin='';
			$czclass=2;
			$msje=0;$msbs=0;

			if($money>=$xxczje){
				$msje = $money*$xxczzsbs/100;
				$msbs = $xxczzsbs;
			}

			$zsbs = $hyzsbs;
			$zsje = $money*$hyzsbs/100;
			$chongzhi = new ChongZhi();

			if($chongzhi->WeiXinRecharge($czadmin,$ddbh,$money,$user['username'],'0','0',$czclass,$xxbank,$time,get_ip(),'0',$liuyan,$zsje,$zsbs,$msje,$msbs,$usclass,$account,'0.00',$user['je'])){
				return json_encode(['status'=>1]);
			}else{
				return json_encode(['status'=>0,'msg'=>'充值失败！']);
			}
		}
	}
	public function bankDetail(){
		$username = input('name','');
		$detail = Db::name('username')->alias("a")->join('__BANK__ b','a.bankname=b.id','LEFT')->where(['username'=>$username])->field("b.bankname,a.bankno,a.bankren,a.banksf,a.banksq,a.mobile,a.bank_zhihang")->find();
		$row = array(
				'result'=>0,
		);
		if( $detail && !empty($detail['bankno']) ){
			$row['result'] = 1;
			$detail['warn'] = Db::name('xt_tixian')->where('id',1)->value('test');
			$row['datas'] = $detail;
		}
		echo json_encode($row,JSON_UNESCAPED_UNICODE);
	}
	public function yaoqingmaDelete(){
		$key = input('key');
		$username = $this->user_all['username'];
		$user = Db::name('username')->where('username',$username)->field('id,tjm')->find();
		$yaoqingma = explode('|',$user['tjm']);

		foreach($yaoqingma as $k=>$v){
			$yzm = explode('-',$v);
			if( isset($yzm[0]) && $yzm[0]==$key ) unset($yaoqingma[$k]);
		}

		$yaoqingma_new = implode('|',$yaoqingma);
		if(Db::name('username')->where('username',$username)->update(array('tjm'=>$yaoqingma_new))){
			echo 1;
		}else{
			echo 2;
		}
	}
	public function zhmx(){

		$name = input('name',0);;
		if( !$name ) {
			android_login('请先登录账号！',$this->appfrom);
		}
		//0:今天,1:昨天,2:本周,3:本月,4:上月
		$date = input('date',0);
		$page = input('page',1);
		$limit = 20;
		$total = 0;
		switch( intval($date) ){
			case 1:
				$begin = strtotime( date("Y-m-d 00:00:00",strtotime("-1 day")) );
				$end = strtotime( date("Y-m-d 23:59:59",strtotime("-1 day")) );
				break;
			case 2:
				$begin = mktime( 0, 0 , 0, date("m"), date("d")-date("w")+1, date("Y") );
				$end = mktime( 23,59,59,date("m"), date("d")-date("w")+7, date("Y") );
				break;
			case 3:
				$begin = mktime(0, 0 , 0,date("m"),1,date("Y"));
				$end = mktime(23,59,59,date("m"),date("t"),date("Y"));
				break;
			case 4:
				$begin = mktime(0, 0 , 0,date("m")-1,1,date("Y"));
				$end = mktime(23,59,59,date("m") ,0,date("Y"));
				break;
			default:
				$begin = strtotime(date("Y-m-d 00:00:00",time()));
				$end = strtotime(date("Y-m-d 23:59:59",time()));

		}
		//0全部；1公司入款,2线下入款,3人工入款,4活动优惠,5投注退款,6提款退还,7代理返佣，8中奖派送，9提现记录，10投注记录，11现金交易，12投注退还本金
		$type = input('type',0);
		$list = [];
		switch( intval($type)){
			case 1:
				$total = Db::name("chongzhi_list")->where(['zt'=>1,'czclass'=>1,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->count();
				$list = Db::name("chongzhi_list")->field("1 as label,je,czhje as hje,cztime as time")->where(['zt'=>1,'czclass'=>1,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->order("cztime DESC")->page($page,$limit)->select();
				break;
			case 2:
				$total = Db::name("chongzhi_list")->where(['zt'=>1,'czclass'=>2,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->count();
				$list = Db::name("chongzhi_list")->field("2 as label,je,czhje as hje,cztime as time")->where(['zt'=>1,'czclass'=>2,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->order("cztime DESC")->page($page,$limit)->select();
				break;
			case 3:
				$total = Db::name("chongzhi_list")->where(['zt'=>1,'czclass'=>3,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->count();
				$list = Db::name("chongzhi_list")->field("3 as label,je,czhje as hje,cztime as time")->where(['zt'=>1,'czclass'=>3,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])->order("cztime DESC")->page($page,$limit)->select();
				break;
			case 4:
				$total = Db::name("caijin_list")->where(['zzhdid'=>['>',0],'username'=>$name])->whereTime("fstime",'between',[$begin,$end])->count();
				$list = Db::name("caijin_list")->field("4 as label,cjje as je,cjhje as hje,fstime as time")->where(['zzhdid'=>['>',0],'username'=>$name])->whereTime("fstime",'between',[$begin,$end])->order("fstime DESC")->page($page,$limit)->select();
				break;
			case 5:
				$total = Db::name('touzhu_list_tk')->where(['username'=>$name])->whereTime("tktime",'between',[$begin,$end])->count();
				$list = Db::name('touzhu_list_tk')->field("5 as label,tzje as je,tkqje as hje,tktime as time")->where(['username'=>$name])->whereTime("tktime",'between',[$begin,$end])->order("tktime DESC")->page($page,$limit)->select();
				break;
			case 7:
				$total = Db::name("day_agent")->where(['agent'=>$name])->whereTime("add_time",'between',[$begin,$end])->count();
				$list = Db::name("day_agent")->field("7 as label,balance as je,fyqje as hje,add_time as time")->where(['agent'=>$name])->whereTime("add_time",'between',[$begin,$end])->order("add_time DESC")->page($page,$limit)->select();
				break;
			case 9:
				$total = Db::name("tixian_list")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->count();
				$list = Db::name("tixian_list")->field("9 as label,txje as je,txhje as hje,txtime as time")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->order("txtime DESC")->page($page,$limit)->select();
				break;
			case 6:
				$total = Db::name("tixian_list_no")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->count();
				$list = Db::name("tixian_list_no")->field("6 as label,txje as je,0 as hje,txtime as time")->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end])->order("txtime DESC")->page($page,$limit)->select();
				break;
			case 8:
				$total = Db::name("touzhu_list_pc")->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end])->count();
				$list = Db::name("touzhu_list_pc")->field("8 as label,zjje as je,tzhje as hje,tz_time as time")->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end])->order("tz_time DESC")->page($page,$limit)->select();
				break;
			case 10:
				$total = Db::name("touzhu_list_ok")->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end])->count();
				$list = Db::name("touzhu_list_ok")->field("10 as label,tzje as je,tzhje as hje,tz_time as time")->where(['username'=>$name,'ifqs'=>1])->whereTime("tz_time",'between',[$begin,$end])->order("tz_time DESC")->page($page,$limit)->select();
				break;
			default:
				$list = Db::field("id,czclass as label,je,czhje as hje,cztime as time")->table("kkty_chongzhi_list")->where(['zt'=>1,'username'=>$name])->whereTime("cztime",'between',[$begin,$end])
						->union(function($query) use($name,$begin,$end){
							$query->field('id,4 as label,cjje as je,cjhje as hje,fstime as time')->table('kkty_caijin_list')->where(['zzhdid'=>['>',0],'username'=>$name])->whereTime("fstime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,5 as label,tzje as je,tkqje as hje,tktime as time')->table('kkty_touzhu_list_tk')->where(['username'=>$name])->whereTime("tktime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,7 as label,balance as je,fyqje as hje,add_time as time')->table('kkty_day_agent')->where(['agent'=>$name])->whereTime("add_time",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,9 as label,txje as je,txhje as hje,txtime as time')->table('kkty_tixian_list')->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,6 as label,txje as je,0 as hje,txtime as time')->table('kkty_tixian_list_no')->where(['username'=>$name])->whereTime("txtime",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,8 as label,zjje as je,tzhje as hje,tz_time as time')->table('kkty_touzhu_list_pc')->where(['username'=>$name,'ifqs'=>1,'zjje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,12 as label,fdje as je,tzhje as hje,tz_time as time')->table('kkty_touzhu_list_ok')->where(['username'=>$name,'ifqs'=>1,'fdje'=>['>',0]])->whereTime("tz_time",'between',[$begin,$end]);
						})->union(function($query) use($name,$begin,$end){
							$query->field('id,10 as label,tzje as je,tzhje as hje,tz_time as time')->table('kkty_touzhu_list_ok')->where(['username'=>$name,'ifqs'=>1])->whereTime("tz_time",'between',[$begin,$end]);
						})->select();
				$total = count($list);
				array_multisort(array_column($list,'time'),SORT_DESC,array_column($list,'hje'),SORT_DESC,$list);
				$list = array_slice($list,($page-1)*$limit,$limit);
		}
		foreach( $list as &$v ){
			//0全部；1公司入款,2线下入款,3人工入款,4活动优惠,5投注退款,6提款退还,7代理返佣，8中奖派送，9提现记录，10投注记录，11现金交易

			switch( intval($v['label'])){
				case 1:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '公司入款';
					break;
				case 2:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '线下入款';
					break;
				case 3:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '人工入款';
					break;
				case 4:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '活动优惠';
					break;
				case 5:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '投注撤单';
					$v['hje'] = floatval($v['hje'])+floatval($v['je']);
					break;
				case 6:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '提款退还';
					$v['hje'] = '---';
					break;
				case 7:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '代理返佣';
					$v['hje'] = floatval($v['hje'])+floatval($v['je']);
					break;
				case 8:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '中奖派送';
					$v['hje'] = floatval($v['hje'])+floatval($v['je']);
					break;
				case 9:
					$v['label'] = '提现记录';
					$v['je'] = '-'.$v['je'];
					break;
				case 10:
					$v['label'] = '投注记录';
					$v['je'] = '-'.$v['je'];
					break;
				case 11:
					$v['je'] = '+'.$v['je'];
					$v['label'] = '现金交易';
					break;
				case 12:
					$v['label'] = '和局退本金';
					$v['je'] = '+'.$v['je'];
					$v['hje'] = floatval($v['hje'])+floatval($v['je']);
					break;
				default:
					$v['label'] = '未知';
					$v['je'] = '0';
					$v['hje'] = '0';
			}
		}
		unset($v);
		$ret['result'] = 1;
		$ret['ResultMsg'] = '信息';
		$ret['datas'] = [
				'list' => $list,
				'page' => $page,
				'total' => $total,
				'total_page' => ceil($total/$limit)
		];
		echo json_encode($ret,JSON_UNESCAPED_UNICODE);
	}
}